/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DAO;

import DTO.DOIBONG;

import java.sql.Connection;
import java.sql.ResultSet;
import java.util.ArrayList;


public class DoibongDAO {
    Connect con= new Connect();
    Connection cont;
    //Tao ket noi
    public DoibongDAO()
    {
        cont=con.Connect("sa","123456");
 
    }
    //Lay du lieu tu bang doibong
    public ResultsModel Getdata()
    { 
        Result rs= new Result();
      String []title={"Mã_DB","Tên_DB","SL Cầu thủ","HLV","Sân","Tổng Trận","Trận thắng","Trận thua","Trận hòa","Tổng bàn thắng","Tổng bàn thua"};
        return rs.GetResult(cont,"Select * from VIEW_DOIBONG",title);
    }
    public ResultSet Getdata1()
    {
        String sqlGetData= "select * from DOibong";
        return con.GetdataTable(sqlGetData);
    }
       public String GetMaFTenDoibong(DOIBONG db)
      {
          return con.GetMaDK("MA_DB", "DOIBONG", "TEN_DB",db.getTenDB());
      }
    public void Insert(DOIBONG db)
    {
       
        ArrayList <String> a= new ArrayList();
        a.add("Thongbao");
        a.add(db.getMaDB());
        a.add(db.getTenDB());
        a.add(Integer.toString(db.getSlCauThu()));
        a.add(db.getSan().getMasan());
        a.add(db.getHlv().getNguoi().getManguoi());
        a.add(Integer.toString(db.getSoTranThiDau()));
        a.add(Integer.toString(db.getSoTranThang()));
        a.add(Integer.toString(db.getSoTranThua()));
        a.add(Integer.toString(db.getSoTranHoa()));
        a.add(Integer.toString(db.getBanThang()));
        a.add(Integer.toString(db.getBanThua()));
        
        String spThemDoibong = "{Call spThemDoibong(?,?,?,?,?,?,?,?,?,?,?,?)}";
        con.Insert(spThemDoibong, a, true);
    }
    public void Update(DOIBONG db)
    {
       
        ArrayList <String> a= new ArrayList();
        a.add("Thongbao");
        a.add(db.getMaDB());
        a.add(db.getTenDB());
        a.add(Integer.toString(db.getSlCauThu()));
        a.add(db.getSan().getMasan());
        a.add(db.getHlv().getNguoi().getManguoi());
        a.add(Integer.toString(db.getSoTranThiDau()));
        a.add(Integer.toString(db.getSoTranThang()));
        a.add(Integer.toString(db.getSoTranThua()));
        a.add(Integer.toString(db.getSoTranHoa()));
        a.add(Integer.toString(db.getBanThang()));
        a.add(Integer.toString(db.getBanThua()));
        
        String spSuaDoibong = "{Call spSuaDoibong(?,?,?,?,?,?,?,?,?,?,?)}";
        con.Update(spSuaDoibong, a, true);
    }
     public void Delete(DOIBONG db)
     {
         String sqlDelete="Delete DoiBong where ma_db='"+db.getMaDB()+"'";
         con.Update(sqlDelete, null, false);
     }
}
